package com.xbao.controller;

import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.req.StuContractReq;
import com.xbao.model.vo.FeeTotalVo;
import com.xbao.model.vo.StuContractVo;
import com.xbao.service.StuContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/25.
 */
@Api(value = "/contract", tags = "contract")
@RequestMapping(value = "contract")
@Controller
@EnableAutoConfiguration
public class ContractController extends BaseController {
    @Resource
    private StuContractService feeService;

    /**
     * @param feeCommRequest
     * @return
     */
    @ApiOperation(value = "addContract", notes = "addContract")
    @RequestMapping(value = "/addContract", method = RequestMethod.POST)
    @ResponseBody
    public CommResult addContract(@RequestBody CommRequest<StuContractReq> feeCommRequest) {
        feeService.addContract(feeCommRequest.getData());
        return result();

    }

    @ApiOperation(value = "recharge", notes = "recharge")
    @RequestMapping(value = "/recharge", method = RequestMethod.POST)
    @ResponseBody
    public CommResult recharge(@RequestBody CommRequest<StuContractReq> feeCommRequest) {
        feeService.addContract(feeCommRequest.getData());
        return result();

    }

    @ApiOperation(value = "backCharge", notes = "backCharge")
    @RequestMapping(value = "/backCharge", method = RequestMethod.POST)
    @ResponseBody
    //课时数,金额  备注
    public CommResult backCharge(@RequestBody CommRequest<StuContractReq> feeCommRequest) {
        feeService.addContract(feeCommRequest.getData());
        return result();

    }


    /**
     * @param feeVoCommRequest
     * @return
     */
    @ApiOperation(value = "queryContractPage", notes = "queryContractPage")
    @RequestMapping(value = "/queryContractPage", method = RequestMethod.POST)
    @ResponseBody
    public CommResult<List<StuContractVo>> queryContractPage(@RequestBody CommRequest<StuContractReq> feeVoCommRequest) {
        List<StuContractVo> fee = feeService.queryContractPage(feeVoCommRequest.getData());
        return new CommResult<>(fee);
    }

    /**
     * @param stuContractReqCommRequest
     * @return
     */
    @ApiOperation(value = "contractDetail", notes = "contractDetail")
    @RequestMapping(value = "/contractDetail", method = RequestMethod.POST)
    @ResponseBody
    public CommResult<StuContractVo> contractDetail(@RequestBody CommRequest<StuContractReq> stuContractReqCommRequest) {
        StuContractVo vo = feeService.detailContract(stuContractReqCommRequest.getData().getId());
        return new CommResult<StuContractVo>(vo);
    }

    /**
     * @param
     * @return
     */
    @ApiOperation(value = "feeTotal", notes = "feeTotal")
    @RequestMapping(value = "/feeTotal", method = RequestMethod.POST)
    @ResponseBody
    public CommResult<FeeTotalVo> feeTotal(@RequestBody CommRequest<StuContractReq> stuFeeReqCommRequest) {
        Long begintime = stuFeeReqCommRequest.getData().getBegintime();
        Long endtime = stuFeeReqCommRequest.getData().getEndtime();
        Long orgid = stuFeeReqCommRequest.getData().getOrgid();
        FeeTotalVo vo = feeService.queryFeeTotalVo(begintime, endtime, orgid);
        return new CommResult<FeeTotalVo>(vo);

    }

}
